local chuifeng = fk.CreateSkill{
    name = "jinhs__chuifeng",
}

Fk:loadTranslationTable{
  ["jinhs__chuifeng"]="椎锋",
  [":jinhs__chuifeng"]="出牌阶段限一次，你可以将一名与你势力相同的角色的场上的一张牌当【决斗】使用，若不为你的牌，你不能响应此牌；若为武器牌，此牌伤害+1。",

  ["#jinhs__chuifeng-avtive"] = "椎锋：你可以将一名与你势力相同的角色的场上的一张牌当【决斗】使用",
  ["#jinhs__chuifeng-duel"]="椎锋：将 %dest 场上的一张牌当【决斗】使用。",
  ["#jinhs__chuifeng-use"]="椎锋：请指定使用 %arg 的目标。",

  ["$jinhs__chuifeng1"]="率军冲锋，不惧刀枪所阻！",
  ["$jinhs__chuifeng2"]="登锋履刃，何妨马革裹尸！",
}

local H = require "packages.ol_hegemony.util"

chuifeng:addEffect("active",{
    anim_type = "offensive",
    prompt = "#jinhs__chuifeng-avtive",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
      return player:usedSkillTimes(chuifeng.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected, cards)
      local targetx = to_select
      if targetx and #targetx:getCardIds("ej") >0 and H.compareKingdomWith(player, targetx) then
      for _, cid in ipairs(targetx:getCardIds("ej")) do
        local card = Fk:cloneCard("duel")
        card.skillName = chuifeng.name
        card.subcards= {cid}
        return player:canUse(card) and not player:prohibitUse(card)
        and #table.filter(Fk:currentRoom().alive_players, function (p) return not player:isProhibited(p, card) end) > 0
        end
      end
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local cardsid = {}
        if target and #target:getCardIds("ej") > 0 then
            for _, cid in ipairs(target:getCardIds("ej")) do
                local card = Fk:cloneCard("duel")
                card.skillName = chuifeng.name
                card.subcards = { cid }
                if player:canUse(card) and not player:prohibitUse(card) and #table.filter(room.alive_players, function(p)
                    return not player:isProhibited(p, card) end) > 0 then
                    table.insert(cardsid, cid)
                end
              end
            if #cardsid > 0 then
                local c = room:askToChooseCard(player, {
                    target = target,
                    flag = { card_data = {{ chuifeng.name, cardsid }} },
                    skill_name = chuifeng.name,
                    prompt = "#jinhs__chuifeng-duel::" .. target.id,
                })
                if c then
                    local slash = Fk:cloneCard("duel")
                    slash.skillName = chuifeng.name
                    slash:addSubcard(c)
                    local max_num = slash.skill:getMaxTargetNum(player, slash)
                    local targets = {}
                    for _, p in ipairs(room.alive_players) do
                         if player ~= p and not player:isProhibited(p, slash) then
                         table.insert(targets, p)
                      end
                    end
                    if #targets > 0 or max_num > 0 then
                        local tos = room:askToChoosePlayers(player, {
                            targets = targets,
                            min_num = 1,
                            max_num = max_num,
                            prompt = "#jinhs__chuifeng-use:::"..slash:toLogString(),
                            skill_name = chuifeng.name,
                            cancelable = false,
                        })
                    if #tos > 0 then
                        local use = {
                            from = player,
                            tos = tos,
                            card = slash,
                        }
                    if Fk:getCardById(c).sub_type == Card.SubtypeWeapon then
                        use.additionalDamage = 1
                    end
                if (room:getCardOwner(c) == nil) or (room:getCardOwner(c) ~= player)
                or (room:getCardArea(c) ~= player.Hand and room:getCardArea(c) ~= player.Equip) then
                  use.disresponsiveList = use.disresponsiveList or {}
                  table.insertIfNeed(use.disresponsiveList, player)
                end
                room:useCard(use)
              end
            end
          end
        end
      end
    end,
})

return chuifeng